package com.om.abom.config;

import com.om.abom.ws.WsHandlerManageServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
@Slf4j
public class WebSocketConfig implements WebSocketConfigurer
{
    @Autowired
    WebSocketHandler webSocketHandler;

    @Autowired
    WsHandlerManageServer wsHandlerManageServer;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        log.info("websocket 启动成功!");

        registry.addHandler(webSocketHandler, "/ws/serverStatus")
                .addHandler(wsHandlerManageServer, "/ws/manageServer")
                .setAllowedOrigins("*");
    }
}